//
//  CommonMethod.h
//  OneCard
//
//  Created by sally on 16/2/16.
//  Copyright © 2016年 koalac. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <MBProgressHUD.h>

typedef NS_ENUM(NSUInteger, ButtonItemType) {
  ButtonItemType_Gray,//灰色导航栏按钮
  ButtonItemType_Orange,//橘色导航栏按钮
  ButtonItemType_White,//橘色导航栏按钮
};

typedef NS_ENUM(NSUInteger, NavStyle) {
  NavStyle_Black,//黑
  NavStyle_Normal,//常用
};

@interface CommonMethod : NSObject
singleton_interface(CommonMethod)

//创建加载显示
- (MBProgressHUD *)createProgressHUDInView:(UIView *)view withMessage:(NSString *)message;

//在View中显示Toast
- (void)showToastInCenter:(UIView *)view withMessage:(NSString *)message;
//显示提示框
- (void)showAlertMessage:(NSString *)message;

//设置导航栏btnItem
- (void)setNavButtonItem:(UIBarButtonItem *)buttonItem type:(ButtonItemType)type;

//导航栏使用图片创建左右按钮
- (UIButton *)navigationItemWithImage:(NSString *)imageName;
//获取当前顶层的navController
- (UINavigationController *)getCurrNavController;
//获取当前顶层的viewController
- (UIViewController *)getCurrViewController;

//保存到userDefault
- (void)setUserDefaultsWithKey:(NSString *)key andValue:(id)value;
//从userDefault取出值
- (NSString *)getUserDefaultsWithKey:(NSString *)key;
//从userDefault删除key
- (void)delUserDefaultsWithKey:(NSString *)key;

//UITableView隐藏多余的分割线
- (void)setExtraCellLineHidden:(UITableView *)tableView;
//补全分割线
- (void)fullSperatorLine:(UITableView *)tableView;

//压缩图片
- (UIImage *)compressImage:(UIImage *)image;

//图片缩放
- (UIImage *)fitSmallImage:(UIImage *)originImage
                  wantSize:(CGSize)wantSize
                  fitScale:(BOOL)flag;
//图片沿另外图片剪裁
- (UIImage*)maskImage:(UIImage *)image withMask:(UIImage *)maskImage;

//获取文本高度
- (float) heightForString:(NSString *)value maxSize:(CGSize)maxSize attrs:(NSDictionary *)attrs;

//设置view相对于superview的约束，-1表示不设置
- (void)setEdge:(UIView *)superview
           view:(UIView *)view
      edgeInset:(UIEdgeInsets)inset;
//添加左右间隔
- (void)addHorMargin:(UIView *)leftView
           rightView:(UIView *)view
               width:(CGFloat)width;
//添加上下间隔
- (void)addVerMargin:(UIView *)topView
          bottomView:(UIView *)view
               width:(CGFloat)width;
//定制宽高
- (void)addConstraintWidth:(CGFloat)width
                    height:(CGFloat)height
                      view:(UIView *)view;
- (NSLayoutConstraint *)findFirstConstraint:(UIView *)parentView
                                  firstItem:(id)firstItem
                                  attribute:(NSLayoutAttribute)attribute;
- (NSLayoutConstraint *)findSecondConstraint:(UIView *)parentView
                                  secondItem:(id)secondItem
                                   attribute:(NSLayoutAttribute)attribute;

//删除所有tmp文件下的plist文件
- (void)deleteAllPlist:(void (^)(BOOL isSuccess))block;

//获取本地版本号
- (NSString *)getLocalVersion;

//设置按钮上图下文
- (void)setBtnDownTextStyle:(UIButton *)btn;

//设置导航栏风格
- (void)setNavAndStatusBar:(UINavigationBar *)navBar style:(NavStyle)style;

// json转字典
- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString;

@end
